package com.runtu.domain.activity.service.discount.impl;

import com.runtu.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
import com.runtu.domain.activity.service.discount.AbstractDiscountCalculateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @ClassName MJCalculateService
 * @Description 满减优惠计算
 * @date 2025/7/19 20:34
 * @Version 1.0
 */
@Slf4j
@Service("MJ")
public class MJCalculateService extends AbstractDiscountCalculateService {


    @Override
    protected BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount) {

        //首先获取满多少-多少  110，10这种形式
        String marketExpr = groupBuyDiscount.getMarketExpr();
        String[] split = marketExpr.split(",");
        BigDecimal x= new BigDecimal(split[0]);
        BigDecimal y= new BigDecimal(split[1]);
        
        if (originalPrice.compareTo(x) < 0){
            return originalPrice;
        }

        BigDecimal realPrice=originalPrice.subtract(y);//originalPrice-y
        if (realPrice.compareTo(BigDecimal.ZERO) <= 0){
            return new BigDecimal(0.01);
        }

        return realPrice;
    }
}
